<template>
  <v-app id="inspire">
    <v-content>
      <v-container >
        <v-snackbar
          v-model="snackbar"
        >
          {{ text }}
          <v-btn
            color="pink"
            text
            @click="success"
          >
            Close
          </v-btn>
        </v-snackbar>
        <h1 style="text-align: center">To Be Pre-Reviewed</h1>
        <displayList
          :_title="MyReview"
          :_items="tobeReviewed"
          :_item-per-page="4"
          @wantToReview="review"
        >
        </displayList>
        <v-divider></v-divider>

        <h1  style="text-align: center">To Be CheckReviewed Firstly</h1>
        <displayList
          :_title="MyReview"
          :_items="contributionToBeCheckReviewedFirstly"
          :_item-per-page="4"
          @wantToReview="changeReview"
          @wantToConfirm="confirm"
        >
        </displayList>
        <v-divider></v-divider>

        <h1  style="text-align: center">Waiting For Rebuttal</h1>
        <displayList
          :_items="contributionsWaitingForRebuttal"
          :_item-per-page="4"
        >
        </displayList>
        <v-divider></v-divider>

        <h1  style="text-align: center">To Be CheckReviewed Secondly</h1>
        <displayList
          :_title="MyReview"
          :_items="contributionsToBeCheckReviewedSecondly"
          :_item-per-page="4"
          @wantToReview="secondReview"
        >
        </displayList>
        <v-divider></v-divider>
        <side-bar></side-bar>
      </v-container>
    </v-content>
  </v-app>
</template>

<script>
import DisplayList from '../DisplayList'
import SideBar from './SideBar'
import store from '../../store'
export default {
  name: 'ReviewDashboard',
  components: {
    SideBar,
    DisplayList
  },
  data () {
    const generateContributedToBeReviewed = _ => {
      const conferences = []
      this.$axios.post('/contributionToBeReviewed', store.state.userName)
        .then(resp => {
          if (resp != null) {
            var response = resp.data
            response.forEach((contribution, index) => {
              conferences.push({
                // identity : "Author",
                // contributor : contribution.contributor,
                abbrName: contribution.meetingFullName,
                MeetingFullName: contribution.meetingFullName,
                FileTitle: contribution.fileTitle,
                FileAbstract: contribution.fileAbstract,
                contributor: contribution.contributor,
                status: contribution.status
                // topics: contribution.topics
              })
            })
            return conferences
          } else return null
        })
        .catch(error => {
          console.log(error)
        })
      return conferences
    }
    const generateContributionToBeCheckReviewedFirstly = _ => {
      const conferences = []
      this.$axios.post('/contributionToBeCheckReviewedFirstly', store.state.userName)
        .then(resp => {
          if (resp != null) {
            var response = resp.data
            response.forEach((contribution, index) => {
              conferences.push({
                // identity : "Author",
                // contributor : contribution.contributor,
                abbrName: contribution.meetingFullName,
                MeetingFullName: contribution.meetingFullName,
                FileTitle: contribution.fileTitle,
                FileAbstract: contribution.fileAbstract,
                contributor: contribution.contributor,
                status: contribution.status,
                statusMessage: 'Second Discussion'
                // topics: contribution.topics
              })
            })
            return conferences
          } else return null
        })
        .catch(error => {
          console.log(error)
        })
      return conferences
    }
    const generateContributionsWaitingForRebuttal = _ => {
      const conferences = []
      this.$axios.post('/contributionsWaitingForRebuttal', store.state.userName)
        .then(resp => {
          if (resp != null) {
            var response = resp.data
            response.forEach((contribution, index) => {
              conferences.push({
                // identity : "Author",
                // contributor : contribution.contributor,
                abbrName: contribution.meetingFullName,
                MeetingFullName: contribution.meetingFullName,
                FileTitle: contribution.fileTitle,
                FileAbstract: contribution.fileAbstract,
                contributor: contribution.contributor,
                status: contribution.status
                // topics: contribution.topics
              })
            })
            return conferences
          } else return null
        })
        .catch(error => {
          console.log(error)
        })
      return conferences
    }
    const generateContributionsToBeCheckReviewedSecondly = _ => {
      const conferences = []
      this.$axios.post('/contributionsToBeCheckReviewedSecondly', store.state.userName)
        .then(resp => {
          if (resp != null) {
            var response = resp.data
            response.forEach((contribution, index) => {
              conferences.push({
                // identity : "Author",
                // contributor : contribution.contributor,
                abbrName: contribution.meetingFullName,
                MeetingFullName: contribution.meetingFullName,
                FileTitle: contribution.fileTitle,
                FileAbstract: contribution.fileAbstract,
                contributor: contribution.contributor,
                status: contribution.status
                // topics: contribution.topics
              })
            })
            return conferences
          } else return null
        })
        .catch(error => {
          console.log(error)
        })
      return conferences
    }
    return {
      MyReview: 'My Review',
      tobeReviewed: generateContributedToBeReviewed(),
      contributionToBeCheckReviewedFirstly: generateContributionToBeCheckReviewedFirstly(),
      contributionsWaitingForRebuttal: generateContributionsWaitingForRebuttal(),
      contributionsToBeCheckReviewedSecondly: generateContributionsToBeCheckReviewedSecondly(),
      snackbar: false,
      text: ''
    }
  },
  methods: {
    success() {
      this.snackbar = false
      // location.reload()
    },
    review (item) {
      this.$router.push({
        path: '/workspace/review/' + item.MeetingFullName,
        query: {
          contributor: item.contributor,
          fileTitle: item.FileTitle,
          type: 1
          // topics: item.topics
        }
      })
      // this.$router.replace('/workspace/review/'+item.contributor+'?'+item.FileTitle)
    },
    confirm (item) {
      this.$axios.post('/refuseToChangeReview', {
        contributor:null,
        title: item.FileTitle,
        pcMember: store.state.userName,
        mark:null,
        comment:null,
        confidence:null,
        meetingName:item.MeetingFullName
      })
        .then(resp => {
          console.log("true?"+resp.data)
            if (resp.status === 200) {
              if(resp.data === true){
                this.text = '确认成功'
                this.snackbar = true
                location.reload()
              } else {
                this.text = '你还没有发言过'
                this.snackbar = true
              }
              // location.reload()
            } else {
              this.text = '确认失败'
              this.snackbar = true
            }
        })
        .catch(error => {
          console.log(error)
        })
    },
    changeReview(item) {
      this.$router.push({
        path: '/workspace/review/' + item.MeetingFullName,
        query: {
          contributor: item.contributor,
          fileTitle: item.FileTitle,
          type: 2
          // topics: item.topics
        }
      })
    },
    secondReview(item) {
      this.$router.push({
        path: '/workspace/review/' + item.MeetingFullName,
        query: {
          contributor: item.contributor,
          fileTitle: item.FileTitle,
          type: 3
          // topics: item.topics
        }
      })
    }
  }
}
</script>
